package thread;

public class Mgr02 {
    private static volatile Mgr02 INSTANCE;

    private Mgr02() {

    }

    public static Mgr02 getInstance() {
        if (INSTANCE == null) {
            synchronized (Mgr02.class) {
                // 双重检查
                if (INSTANCE == null) {
                    try {
                        Thread.sleep(1);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                    INSTANCE = new Mgr02();
                }
            }
        }

        return INSTANCE;
    }

    public static void m() {
        Mgr02 mgr02 = getInstance();
        System.out.println(mgr02.hashCode());
    }

    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            new Thread(Mgr02::m).start();
        }
    }
}
